package co.fitstart.mobile.web.controller.profile;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import co.fitstart.entity.credit.Credit;
import co.fitstart.entity.credit.CreditTransaction;
import co.fitstart.entity.user.User;
import co.fitstart.mobile.service.CreditService;
import co.fitstart.mobile.web.interceptor.MobileDetect;
import co.fitstart.mobile.web.interceptor.Router;
import co.fitstart.mobile.web.resolver.Secure;

@RequestMapping("/profile")
@Controller
public class ProfileCreditController {
    
    @Autowired
    private CreditService creditService;
    
    /**
     * 我的积分
     * @param user 
     * 
     * @return
     */
    @RequestMapping(value = "/credit-records", method = RequestMethod.GET)
    @Router(targetUrl = "/required-wechat")
    @MobileDetect
    public ModelAndView listCredits(@Secure User user) {
        ModelAndView modelAndView = new ModelAndView("profile/credit/credit-transaction-record");
        
        Credit credit = creditService.generallyLoad(user);
        
        List<CreditTransaction> creditTransactions = creditService.listCreditTransaction(credit);
        
        modelAndView.addObject("credit", credit);
        modelAndView.addObject("creditTransactions", creditTransactions);
        
        return modelAndView;
    }
}
